package com.guli.gulimall.product;

import com.aliyun.oss.OSS;
import com.guli.gulimall.product.dao.CategoryDao;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.FileInputStream;
/**
 * @ClassName Demo
 * @Author Hao_YunKai
 * @Date 2021/12/9 15:55
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class Demo {

    @Autowired
    private CategoryDao categoryDao;

    @Autowired
    private OSS ossClient;

    @Value("${alibaba.cloud.oss.bucket}")
    private String bucket;

    @Test
    public void ossTest_2() throws Exception{
        ossClient.putObject(bucket,"admin.jpg",new FileInputStream("C:\\Users\\home\\Desktop\\logo\\vivo_2.png"));
        System.out.println("成功...");
        ossClient.shutdown();
    }

    /*@TestDemo
    public void tree() {
        List<CategoryEntity> list_01 = categoryDao.selectList(new QueryWrapper<CategoryEntity>().eq("parent_cid", 0));
        for (CategoryEntity categoryEntity : list_01) {
            List<CategoryEntity> list_02 = categoryDao.selectList(new QueryWrapper<CategoryEntity>().eq("cat_id", categoryEntity.getCatId()));
            categoryEntity.setChildren(list_02);
            for (CategoryEntity entity : list_02) {
                List<CategoryEntity> list_03 = categoryDao.selectList(new QueryWrapper<CategoryEntity>().eq("cat_id", entity.getCatId()));
                entity.setChildren(list_03);
            }
        }
        for (CategoryEntity categoryEntity : list_01) {
            System.out.println(categoryEntity);
        }
    }*/

    /*@TestDemo
    public void ossTest() throws Exception{
        // yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1（杭州）为例，Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
        String endpoint = "https://oss-cn-shanghai.aliyuncs.com";
        // 阿里云账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维，请登录RAM控制台创建RAM用户。
        String accessKeyId = "LTAI5tMD6EdiQ2UJTXkRr7fk";
        String accessKeySecret = "3irqQ4Fb2HBZNKkhbAJsmeckifmZuM";


        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        // 填写本地文件的完整路径。如果未指定本地路径，则默认从示例程序所属项目对应本地路径中上传文件流。
        InputStream inputStream = new FileInputStream("C:\\Users\\home\\Desktop\\logo\\vivo_2.png");
        // 依次填写Bucket名称（例如examplebucket）和Object完整路径（例如exampledir/exampleobject.txt）。Object完整路径中不能包含Bucket名称。
        ossClient.putObject("img-guli", "Hao_YunKai.png", inputStream);
        System.out.println("Success...");
        // 关闭OSSClient。
        ossClient.shutdown();
    }*/
}
